package com.peak.example;

import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

import java.util.Arrays;
import java.util.List;

/**
 * @author likai
 * @date 2021/11/6 5:01 PM
 * @email likai9376@163.com
 * @desc
 */
public class GatewayExample01 {

    public static void main(String[] args) {
        List<String> routes = Arrays.asList("id", "hello", "haode");
        Flux<String> flux = Flux.fromIterable(routes);
        Mono<String> routeId = Mono.from(flux);
        Mono<Object> objectMono = routeId.flatMap(id -> {
            if (id.equals("hello")) {
                return Mono.empty();
            }
            return Mono.defer(() -> Mono.error(
                    new RuntimeException("RouteDefinition not found: " + routeId)));
        });
        objectMono.subscribe(System.out::println);
    }
}
